package com.junxonline.instant.job;

import lombok.extern.log4j.Log4j2;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 定时任务启动类
 *
 * @author JunX
 * @date 2022-06-17
 */
@Log4j2
@EnableAsync
@EnableAspectJAutoProxy
@MapperScan(basePackages = "com.junxonline.instant.dao.mapper.**.*")
@SpringBootApplication(scanBasePackages = {"com.junxonline.instant.job", "com.junxonline.instant.common.util.job", "com.junxonline.instant.common.util.common"})
public class InstantJobServer {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(InstantJobServer.class, args);
        Environment environment = context.getBean(Environment.class);
        startApplicationOver(environment);
    }

    private static void startApplicationOver(Environment environment) {
        String ip = "";
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            log.error("- Don't get Application host address!");
        }
        log.info("[" + environment.getProperty("spring.application.name") + "] Application running at:");
        log.info("- Local:   http://localhost:" + environment.getProperty("server.port"));
        log.info("- Network: http://" + ip + ":" + environment.getProperty("server.port"));
    }

}
